package com.zk.shop.servlet.sorts;

import com.zk.shop.entity.Sorts;
import com.zk.shop.service.Impl.SortsServiceImpl;
import com.zk.shop.service.SortsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("sorts/AddSortsServlet")
public class AddSortsServlet  extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String sortsname = req.getParameter("sortsname");
        Sorts sorts = new Sorts(sortsname);
        SortsService sortsService = new SortsServiceImpl();
        boolean flag = sortsService.addSorts(sorts);
         if (flag) {
             resp.getWriter().print("增加成功");
             req.getRequestDispatcher("/back/cate.html").forward(req,resp);
         }else {
             resp.getWriter().print("增加失败");
         }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
